<?php
global $TABLES; extract($TABLES);

	$files_array = files_array( _DOCUMENT_ROOT, true, true);
	myPrint( reset($files_array), '$files_array');
	
	echo '<ul class="file_tree">';
		createFilesTree( reset($files_array) );
	echo '</ul>';
	
	function createFilesTree( array $files_array ){
		$extPAGE = array('htm', 'html','php');
		$extTXT = array('txt', 'htm', 'html', 'css','js','php','xml', 'log');
		$extIMG = array('bmp', 'jpg', 'jpeg', 'png','gif','ico');
		
		$onclick = "onclick='var sd=this.parentNode.lastChild.style.display; this.parentNode.lastChild.style.display=sd==\"\"?\"none\":\"\"'";
		foreach($files_array as $path=>$val){
			/* относительный путь */
			$relPath = str_replace( _DOCUMENT_ROOT, '', $path);
			$onclickWO = 'onclick="window.open( this.href, \'admin_popur_edit\', \'width=600,height=800\'); return false;"';
			$prop_but = '<a '.$onclickWO.' title="'.Lang::get('TO_ADJUST').'..." class="setting_but" href="/admin/modules/content/PageProperty.php?page_path='.$relPath.'"></a>';
			if(is_array($val)){
				echo '<li>'.
					$prop_but.
					'<span class="dir" '.(count($val)>0 ?$onclick :'').' >'.
					basename( $path ).' ( '.(count($val)).' )</span>';
					if(count($val)>0){
						echo '<ol class="file_tree" style="display:none;">';
							createFilesTree( $val );
						echo'</ol>';
					}
				echo '</li>';
			}else{
				$path_info = pathinfo($val);
				$fclass = isset($path_info['extension'])? $path_info['extension'] : 'file' ;
				if(in_array($fclass, $extIMG)){
					$isize=array(0=>600,1=>800);
					if(!preg_match('/[А-я]/', $path)) $isize = getimagesize($path);
					$onclickWO = 'onclick="var imW=window.open( this.href, \'admin_popur_image\', \'width='.$isize[0].',height='.$isize[1].'\'); return false;"';
					$val = '<a '.$onclickWO.' href="../show_image.php?src='.$relPath.'">'.$val.'</a>';
				}
					
				echo '<li class="file_tree">'.
					( in_array($fclass, $extPAGE )? $prop_but :'' ).
					'<span class="file '.$fclass.'">'.$val.'</span>'.
				'</li>';
			}
		}
	}
	
	myPrint(DB::getTableProp('page'), 'DB::getTableProp(page)');
?>